package org.workutil.buildpage.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.List;

import org.common.dto.ExcelDto;
import org.common.util.ExcelUtil;
import org.workutil.buildpage.dto.Field;
import org.workutil.buildpage.dto.PageConditionDto;

/**
 * 一个批量生成table页面的工具类
 * 
 * @author fj
 *
 */
public class BuildTinyPageUtil {

	public static void createPage(ExcelDto excelDto, String writePath) throws Exception {
		PageConditionDto dto = excelDto.convertToObj(PageConditionDto.class).get(0);
		dto.setFields(createFieldList(excelDto.getExcelFilePath(), dto.getFieldsName()));
		File file = new File(writePath);
		file.createNewFile();
		OutputStream ou = new FileOutputStream(file);
		ou.write(dto.createFormatString().getBytes());
		ou.close();
	}

	private static List<Field> createFieldList(String excelPath, String name) throws Exception {
		ExcelDto dto = ExcelUtil.initExceldto(excelPath, name);
		List<Field> fields = dto.convertToObj(Field.class);
		return fields;
	}

}
